package cn.js.sip.rat.system.controller;

import cn.js.sip.rat.system.dto.AjaxResult;
import cn.js.sip.rat.system.entity.SysUserEntity;
import cn.js.sip.rat.system.service.SysUserService;
import cn.js.sip.rat.system.util.ShiroUtils;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName: cn.js.sip.rat.system.controller
 * @Description: TODO
 * @author: xuxiaoli
 * @Date: 2019-12-30   14:57
 */
@Controller
@RequestMapping("/system/user/profile")
public class SysProfileController {
    private static final Logger log = LoggerFactory.getLogger(SysProfileController.class);

    private String prefix = "system/user/profile";

    @Autowired
    private SysUserService userService;

    /**
     * 个人信息
     */
    @GetMapping()
    public String profile(ModelMap mmap) {
        Object obj = SecurityUtils.getSubject().getPrincipal();

        SysUserEntity user = ShiroUtils.getSysUser();
        mmap.put("user", user);
//        mmap.put("roleGroup", userService.selectUserRoleGroup(user.getUserId()));
//        mmap.put("postGroup", userService.selectUserPostGroup(user.getUserId()));
        return prefix + "/profile";
    }



    @GetMapping("/resetPwd")
    public String resetPwd(ModelMap mmap) {
//        SysUserEntity user = ShiroUtils.getSysUser();
//        mmap.put("user", userService.selectUserById(user.getUserId()));
        return prefix + "/resetPwd";
    }

    @PostMapping("/resetPwd")
    @ResponseBody
    public AjaxResult resetPwd(String oldPassword, String newPassword) {
//        SysUserEntity user = ShiroUtils.getSysUser();
       /* if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)) {
            user.setSalt(ShiroUtils.randomSalt());
            user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
            if (userService.resetUserPwd(user) > 0) {
                ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
                return success();
            }
            return error();
        } else {
            return error("修改密码失败，旧密码错误");
        }*/
        return AjaxResult.success();
    }



}
